import { ISystem } from '@/types/ISystem';
import { ConfigProvider } from 'ant-design-vue';
import { Theme } from 'ant-design-vue/lib/config-provider/context';
import { defineStore } from 'pinia';
import packageJson from '../../package.json';

interface ISettingState {
	/**
	 * 系统名称
	 */
	_title: string;
	/**
	 * 背景图，背景色
	 */
	_background: string;
	/**
	 * 主题
	 */
	_theme: Theme;
	/**
	 * 阴影颜色
	 */
	_borderShadowColor: string;
}

export const useSystemStore = defineStore('system', {
	state: (): ISettingState => ({
		_title: packageJson.name || 'Admin',
		_background: '#f9f9fc',
		_theme: {
			primaryColor: '#1890ff',
			infoColor: '#1890ff',
			successColor: '#52c41a',
			processingColor: '#1890ff',
			errorColor: '#ff4d4f',
			warningColor: '#faad14',
		},
		_borderShadowColor: '#e6e6e6',
	}),
	getters: {
		title: (state) => state._title,
		background: (state) => state._background,
		theme: (state) => state._theme,
		borderShadowColor: (state) => state._borderShadowColor,
	},
	actions: {
		setTitle(title: string) {
			this._title = title;
		},
		setBackground(background: string) {
			this._background = background;
		},
		setTheme(theme: Theme) {
			this._theme = { ...this._theme, ...theme };
			ConfigProvider.config({
				theme: { ...this._theme },
			});
		},
		setBorderShadowColor(borderShadowColor: string) {
			this._borderShadowColor = borderShadowColor;
		},
	},
});
